package com.asura.app.wechat.base;

import android.os.Bundle;

import com.asura.app.library.base.BaseActivity;
import com.asura.app.wechat.base.mvp.Mvp;

/**
 * Created by Asura on 2017/12/29.
 */

public abstract class BaseMvpActivity<P extends Mvp.Presenter> extends BaseActivity implements Mvp.View<P> {
    private P presenter;

    @Override
    protected void init(Bundle savedInstanceState) {
        presenter = createPresenter();
        if (getPresenter() == null) {
            throw new NullPointerException("presenter can`t be null");
        }
        getPresenter().attachView(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getPresenter().detachView();
    }

    @Override
    public P getPresenter() {
        return presenter;
    }

    protected abstract P createPresenter();
}
